package com.guigu.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.pojo.Orders;
import com.guigu.pojo.PayInfo;
import com.guigu.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController

public class OrdersController {

    @Autowired
    OrdersService ordersService;

    //商户所有类型的订单查询
    @GetMapping("QuerypartOrders.action")
    public Page<Orders>QuerypartOrders(Integer loginUserId,Orders orders,
                                      @RequestParam(value = "pageno",defaultValue = "1")Integer pageno,
                                      @RequestParam(value = "pagesize",defaultValue = "5")Integer pagesize){
        return ordersService.commqueryAllOrders(loginUserId,orders,pageno,pagesize);
    }
    //确认收货
    @PutMapping("editorders.action/{pId}")
    Map editorders(@PathVariable String pId){
        return ordersService.editOrders(pId);
    }

    //用户确认结算添加订单
    @PostMapping("order.action")
    Map addOrder(@RequestBody Orders order){
        return ordersService.addOrder(order);
    }

    //商户确认提货
    @PutMapping("updateOrders.action/{id}")
    Map updateOrders(@PathVariable Integer id){
        return ordersService.updateOrders(id);
    }

    //根据订单id查询订单信息
    @GetMapping("order.action/{id}")
    Orders queryOrderById(@PathVariable Integer id){
        return ordersService.queryOrderById(id);
    }

    //用户订单查询
    @GetMapping("order.action")
    Page<Orders> queryAllOrders(Orders orders,
                                @RequestParam(value = "pageno",defaultValue = "1")Integer pageno,
                                @RequestParam(value = "pagesize",defaultValue = "5")Integer pagesize){
        return ordersService.queryAllOrders(orders,pageno,pagesize);
    }

    //用户操作订单
    @PutMapping("payOrder.action")
    Map payOrder(@RequestBody Orders order){
        return ordersService.payOrder(order);
    }

    //删除订单
    @DeleteMapping("delOrder.action")
    Map delOrder(Orders order){
        return ordersService.delOrder(order);
    }

    //商户订单查询
    @GetMapping("CAOKEordersReturn.action")
    com.guigu.service.utils.Page CAOKEordersReturn(Integer loginUserId, Orders orders,
                                   @RequestParam(value = "pageno",defaultValue = "1")Integer pageno,
                                   @RequestParam(value = "pagesize",defaultValue = "5")Integer pagesize){
        return ordersService.queryAllOrdersReturn(loginUserId,orders,pageno,pagesize);
    }


    //查询需要出库的订单
    @GetMapping("outboundOrder.action")
    public com.guigu.service.utils.Page outboundOrder(Orders orders,@RequestParam(value = "pageno",defaultValue = "1")Integer pageno,
                                                      @RequestParam(value = "pagesize",defaultValue = "5")Integer pagesize){
//        用户退货，总店未出库(说明入库表未有数据)。
//        用户退货，总店已发出出库申请，等待审核，此时用户禁止退货。（只有审核通过才能退货），按钮【发货中】
//        用户退货，总店已出库，商户等待收货，商户按下按钮【确认退货】(总店人员属于线下操作，不需要考虑），总店等待签收，总店入库
        return ordersService.outboundOrder(orders,pageno,pagesize);
    }
}
